package org.smartercontextmobile.communication;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

public class CallSCLocation implements Runnable {
	
	private final String actionSoap = "http://www.smartercontext.org/contextmger/communication/ReceiveCurrentLocation";
	private final String method = "receiveCurrentLocation";
	private final String namespace = "http://www.smartercontext.org/contextmgr/communication/";
	private final String url = "http://192.168.160.59:8080/SmarterContext_Web_Server/services/Communication_Impl?wsdl";
	public boolean statusConnection = false;
	private String JSONdata;
	
	public CallSCLocation(String JSONdata){
		this.JSONdata = JSONdata;
	}

	@Override
	public void run() {
		
		SoapObject request = new SoapObject(namespace, method);
		PropertyInfo property = new PropertyInfo();
		property.setName("location");
		property.setValue(JSONdata);
		property.setType(String.class);
		request.addProperty(property);
		
		PropertyInfo property2 = new PropertyInfo();
		property2.setName("format");
		property2.setValue("json");
		property2.setType(String.class);
		request.addProperty(property2);
		
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
		
		//Transport
		HttpTransportSE transport = new HttpTransportSE(url);
		try {
			transport.call(actionSoap, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		statusConnection = true;

	}

}
